<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="centre/manage/include :: header">
</head>
<link rel="stylesheet" type="text/css" href="/css/plugins/layui/layui.css"/>
<link href="/css/jquery-select/jquery.searchableSelect.css" rel="stylesheet" type="text/css">
<style>
    .province {
        float: left;
        position: relative;
        width: 150px;
        height: 35px;
        line-height: 35px;
        border: 1px solid #fff;
        proddes
    }

    .province:hover {
        border: 1px solid #f7e4a5;
        border-bottom: 1px solid #fffec6;
        background: #fffec6;
    }

    .province .cityall {
        margin-top: 10px;
    }

    .province ul {
        list-style: outside none none;
        position: absolute;
        padding: 0;
        background: #fffec6;
        border: 1px solid #f7e4a5;
        display: none;
        width: auto;
        width: 300px;
        z-index: 999999;
        left: -26px;
        top: 33px;
    }

    .province ul li {
        float: left;
        min-width: 60px;
        margin-left: 20px;
        height: 30px;
        line-height: 30px;
    }

    .province .checkbox-inline {
        padding-top: 0;
    }

    h3, h4, h5 {
        margin: 5px 0;
        font-weight: 600;
    }

    input[type=email], input[type=url], input[type=search], input[type=tel],
    input[type=color], input[type=text], input[type=password], input[type=datetime],
    input[type=datetime-local], input[type=date], input[type=month], input[type=time],
    input[type=week], input[type=number], textarea {
        border-radius: 0 !important;
        color: #858585;
        background-color: #FFF;
        border: 1px solid #D5D5D5;
        padding: 5px 4px 6px;
        font-size: 14px;
        font-family: inherit;
        -webkit-box-shadow: none !important;
        box-shadow: none !important;
        -webkit-transition-duration: .1s;
        transition-duration: .1s;
    }

    .spectable td, .spectable th {
        border: 1px solid #ccc;
        vertical-align: middle;
        text-align: center;
    }

    .spectable th {
        font-weight: bold;
    }

    .spectableinput {
        text-align: center;
    }

    .f {
        border-color: #b94a48;
        -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
        -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
    }

    .table.table-bordered tr th, .table.table-bordered tr td {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    select {
        padding: 3px 4px;
        height: 30px;
    }

    /* .tags {
        display: inline-block;
        padding: 4px 6px;
        color: #777;
        vertical-align: middle;
        background-color: #FFF;
        border: 1px solid #D5D5D5;
        width: 206px;
    } */
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="form-horizontal m-t">
                <div class="form-group">
                    <ul class="nav nav-arrow-next nav-tabs" id="myTab">
                        <li class="active"><a href="#tab_basic">基本信息</a></li>
                        <li><a href="#tab_des">商品描述</a></li>
                        <!--<li><a href="#tab_postage">邮费设置</a></li>-->
                        <!--<li><a href="#tab_commission">佣金费设置</a></li>-->
                        <!--<li><a href="#tab_option">产品规格</a></li>-->
                        <!--<li><a href="#tab_areas">商品售卖区域</a></li>-->
                    </ul>
                </div>
                <div class="tab-content" style="border: 0px;">
                    <div class="tab-pane active" id="tab_basic">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序:</label>
                            <div class="col-sm-6">
                                <input id="displayorder" name="displayorder"
                                       class="form-control" type="number" maxlength="10"><input id="productid" name="id"
                                                                                                type="hidden">
                            </div>
                            <label class="col-sm-2 control-label"
                                   style="text-align: left">数字越大，排名越靠前,限制小于2147483647</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">商品名称:</label>
                            <div class="col-sm-6">
                                <input id="title" name="title" placeholder="必填：商品名称"
                                       class="form-control" type="text" maxlength="50">
                            </div>
                            <label class="col-sm-2 control-label"
                                   style="text-align: left;color:red;">*商品标题(50个汉字以内包括符号)</label>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">商品编号:</label>
                            <div class="col-sm-6">
                                <input id="goodscode" name="goodscode" placeholder="商品编号"
                                       class="form-control" type="text">
                            </div>
                            <label class="col-sm-2 control-label" style="text-align: left">识别商品的唯一编号</label>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"
                                   for="form-field-1"> 商品图片： </label>
                            <div class="col-sm-10">
                                <div class="col-sm-6">
                                    <div class="input-group ">
                                        <input type="text" name="thumb" id="thumb" value="" class="form-control"
                                               autocomplete="off">
                                        <span class="input-group-btn">
												<button class="btn btn-sm btn-default" type="button"
                                                        style="padding:7px 10px"
                                                        onclick="onSelectImgBtnClick('thumb','thumbImg')"
                                                >选择图片</button>
											</span>
                                    </div>
                                    <div class="input-group " style="margin-top:.5em;">
                                        <img src="" id="thumbImg" style="max-width: 30%"/>
                                    </div>
                                </div>
                                <span class="lbl col-xs-12 col-sm-6">
										<span style="color:red;">*商城首页显示的第一张图片</span>
									</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">分类:</label>
                            <div class="col-sm-8">
                                <select data-placeholder="" class="form-control chosen-select"
                                        id="pcate" name="pcate">
                                    <option th:value="0">请选择分类</option>
                                    <option th:each="item: ${categoryList}" th:text="${item.name}"
                                            th:value="${item.id}"></option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"
                                   for="form-field-1"> 商品价格： </label>
                            <div class="col-sm-6">
                                <div class="input-group form-group">
                                    <span class="input-group-addon">现价</span>
                                    <input type="number" name="marketprice" id="marketprice"
                                           class="form-control" value=""/>
                                    <span class="input-group-addon">元 </span>
                                </div>
                                <div class="input-group form-group">
                                    <span class="input-group-addon">原价</span>
                                    <input type="number" name="productprice" id="productprice"
                                           class="form-control" value=""/>
                                    <span class="input-group-addon">元</span>
                                </div>
                                <div class="input-group form-group">
                                    <span class="input-group-addon">成本价</span>
                                    <input type="number" name="costprice" id="costprice"
                                           class="form-control" value=""/>
                                    <span class="input-group-addon">元</span>
                                </div>

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"
                                   for="form-field-1"> 已预约数： </label>
                            <div class="col-sm-6">
                                <div class="input-group">
                                    <input type="text" name="sales" id="sales"
                                           class="form-control" value=""/>
                                    <span class="input-group-addon">件</span>
                                </div>
                                <span class="help-block">商品虚拟预约数</span>
                            </div>
                        </div>
                    </div>


                    <!-- 商品描述部分 开始 -->
                    <div class="tab-pane" id="tab_des">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"
                                   for="form-field-1">商品详情</label>
                            <div class="col-sm-10">
									<textarea id="content" name="content"
                                              style="height: 200px;">
									</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right"
                                   for="form-field-1">商品描述</label>
                            <div class="col-sm-10">
									<textarea id="proddes" name="proddes"
                                              style="height: 200px;width: 500px">
									</textarea>
                            </div>
                        </div>
                    </div>
                    <!-- 商品描述部分 结束-->

                    <!-- 邮费设置部分 开始 -->
                    <div class="tab-pane" id="tab_postage">


                        <!-- 佣金费设置部分 开始 -->
                        <div class="tab-pane" id="tab_commission">


                            <div id="modal-areas" class="modal fade" tabindex="-1">
                                <div class="modal-dialog" style='width: 920px;'>
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button aria-hidden="true" data-dismiss="modal" class="close"
                                                    type="button">×
                                            </button>
                                            <h3>选择区域</h3>
                                        </div>
                                        <div class="modal-body" id="areas-modal-body" style='height: 280px;'>
                                            <div class='province'>
                                                <label class='checkbox-inline' style='margin-left: 20px;'>
                                                    <input type='checkbox' class='cityall' style='margin-top: 12px;'/>
                                                    <span class="citycount" style='color: #ff6600'></span>
                                                </label>
                                            </div>
                                        </div>
                                        <div class="modal-footer">
                                            <a id='btnSubmitArea' class="btn btn-success" data-dismiss="modal"
                                               aria-hidden="true">确定</a>
                                            <a class="btn btn-default" data-dismiss="modal"
                                               aria-hidden="true">关闭</a>
                                        </div>
                                    </div>
                                </div>
                            </div>


                        </div>
                        <!-- 商品售卖区域部分  结束 -->

                    </div>
                    <div class="form-group text-center">
                        <div class="col-sm-8 col-sm-offset-2">
                            <button class="btn btn-primary" onclick="saveProduct()">
                                <i class="fa fa-check"></i>提交
                            </button>
                            <div class="btn btn-danger" onclick="reset()">
                                <i class="fa fa-remove"></i>重置
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>

<div th:include="centre/manage/include::footer"></div>
<script type="text/javascript" src="/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/js/ueditor/custom.js?v=2"></script>
<script type="text/javascript" src="/js/appjs/product/AreaData.js"></script>
<script type="text/javascript" src="/public/ace/js/ace-extra.js"></script>
<script type="text/javascript" src="/js/plugins/layui/layui.js"></script>
<script src="/js/jquery-select/jquery.searchableSelect.js"></script>
<script type="text/javascript">
    $(function () {
        /* $('#pcate').searchableSelect();
        $('#ccate ').searchableSelect(); */
        $('#supplierId').searchableSelect();
        $('#liansuoid').searchableSelect();
    });


    function closeDow() {
        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
        parent.layer.close(index);
    }

    function changeValue() {
        var marketprice = $("#marketprice").val();
        var superiorcommission = $("#superiorcommission").val();
        var superiortype = $("#superiortype option:selected").val();
        if (superiortype == 1) {
            $("#superiorcommission").val(marketprice * (superiorcommission / 100));
            $("#superiortype option:first").prop("selected", 'selected');
        }
    }

    function changeVal() {
        var marketprice = $("#marketprice").val();
        var headcommission = $("#headcommission").val();
        var headtype = $("#headtype option:selected").val();
        if (headtype == 1) {
            $("#headcommission").val(marketprice * (headcommission / 100));
            $("#headtype option:first").prop("selected", 'selected');
        }
    }

    function changeClerkerVal() {
        var marketprice = $("#marketprice").val();
        var clerkercommission = $("#clerkercommission").val();
        var clerkertype = $("#clerkertype option:selected").val();
        if (clerkertype == 1) {
            $("#clerkercommission").val(marketprice * (clerkercommission / 100));
            $("#clerkertype option:first").prop("selected", 'selected');
        }
    }

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#timestart'
            , type: 'datetime'
        });

        laydate.render({
            elem: '#timeend'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#upStartTime', type: 'datetime'
        });

        laydate.render({
            elem: '#upEndTime', type: 'datetime'
        });


    })

    $(function () {
        // tab切换
        $('#myTab a').click(function (e) {
            e.preventDefault();
            $('#myTab li').each(function () {
                $(this).removeClass('active')
            })
            $('.tab-content .tab-pane').each(function () {
                $(this).removeClass('active')
            })
            $(this).parent().addClass('active')
            id = $(this).attr('href')
            $(id).addClass('active');
        })

        // 是否开启门店佣金
        $("#is_fx_commission").click(function () {
            var obj = $(this);
            if (obj.get(0).checked) {
                document.getElementById("superiorcommission").disabled = false;
                document.getElementById("headcommission").disabled = false;
                document.getElementById("clerkercommission").disabled = false;
                document.getElementById("usercommission").disabled = false;
                document.getElementById("superusercommission").disabled = false;
            } else {
                document.getElementById("superiorcommission").disabled = true;
                document.getElementById("headcommission").disabled = true;
                document.getElementById("clerkercommission").disabled = true;
                document.getElementById("usercommission").disabled = true;
                document.getElementById("superusercommission").disabled = true;
            }
        });

        // 是否按时间范围上架
        radioIsChecked();

        // 设置默认限卖时间
        var date = new Date();
        var year = date.getFullYear();
        var mon = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);
        var da = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var h = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var m = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();

        date.setDate(date.getDate() + 1);
        var endyear = date.getFullYear();
        var endmon = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);
        var endda = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var endh = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var endm = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        $("#timestart").val(year + "-" + mon + "-" + da + " 20:30:00");
        $("#timeend").val(endyear + "-" + endmon + "-" + endda + " 20:00:00");
        $("#upStartTime").val(year + "-" + mon + "-" + da + " 20:00:00");
        $("#upEndTime").val(endyear + "-" + endmon + "-" + endda + " 20:00:00");

        /* var date1 = new Date();
        var year1 = date.getFullYear();
        var mon1 = date.getMonth()+1 < 10 ? "0"+ date.getMonth()+1:date.getMonth()+1;
        var da1 = date.getDate() < 10 ? "0"+ date.getDate():date.getDate();

        date1.setDate(date1.getDate()+1);
        var endyear1 = date.getFullYear();
        var endmon1=date.getMonth()+1 < 10 ? "0"+ date.getMonth()+1:date.getMonth()+1;
        var endda1=date.getDate() < 10 ? "0"+ date.getDate():date.getDate();
        $("#upStartTime").val(year1+"-"+mon1+"-"+da1+" 20:00:00");
        $("#upEndTime").val(endyear1+"-"+endmon1+"-"+endda1+" 20:00:00"); */
    })

    // 是否按时间范围上架
    function radioIsChecked() {
        if ($("#isshow3").is(':checked')) {
            $('#shangjiadiv').show();
        } else {
            $('#shangjiadiv').hide();
        }
    }

    function gongyiIsChecked() {
        if ($("#gongyiisshow1").is(':checked')) {
            $('#gongyidiv').show();
        } else {
            $('#gongyidiv').hide();
        }
    }


    function selectAreas() {
        clearSelects();
        var old_citys = $('#areas').html().split(';');
        $('.city').each(function () {
            var parentcheck = false;
            for (var i in old_citys) {
                if (old_citys[i] == $(this).attr('city')) {
                    parentcheck = true;
                    $(this).get(0).checked = true;
                    break;
                }
            }
            if (parentcheck) {
                $(this).parent().parent().parent().parent().find('.cityall').get(0).checked = true;
            }
        });

        $("#modal-areas").modal();
        var citystrs = '';
        $('#btnSubmitArea').unbind('click').click(function () {
            $('.city:checked').each(function () {
                citystrs += $(this).attr('city') + ";";
            });
            $('#areas').html(citystrs);
            $("#selectedareas").val(citystrs);
        })
    }

    function clearSelects() {
        $('.city').attr('checked', false).removeAttr('disabled');
        $('.cityall').attr('checked', false).removeAttr('disabled');
        $('.citycount').html('');
    }

    var yixuanXiaoqu = [];

    showYixuanXiaoqu();

    function headlist(page) {

        var title = $('#select_team_key').val();
        $.ajax({
            type: "post",
            url: "/admin/goods/select_team.html",
            data: {
                title: title,
                page: page
            },
            dataType: "json",
            success: function (data) {
                if (data.length > 0) {
                    $('#ajax-data1').html(data);
                } else {
                    $('#ajax-data1').html("没有门店");
                }
                $('#ajax-data1').html(data);

                match_already_select()
            }
        })
    }

    function match_already_select() {
        var mids = $('#tid_white_list').val()

        //	    		var goods_titles = $('#goods_titles').val()
        idsArr = mids.split(',');
        //	    		titlesArr = goods_titles.split(',');
        for (var i = 0; i < idsArr.length; i++) {
            $('.sel' + idsArr[i]).removeClass("fa-plus")
            $('.sel' + idsArr[i]).addClass("fa-check fa-check1")
        }
    }

    function addTeamWhiteList(id, title) {
        var isHas = false;
        for (var i = 0; i < yixuanXiaoqu.length; i++) {
            var item = yixuanXiaoqu[i];
            if (id == item.id) {
                isHas = true;
                yixuanXiaoqu.splice(i, 1);
            }
        }
        if (isHas) {
            $('.sel' + id).removeClass("fa-check fa-check1")
            $('.sel' + id).addClass("fa-plus")
        } else {
            yixuanXiaoqu.push({
                id: id,
                title: title
            });
            $('.sel' + id).removeClass("fa-plus")
            $('.sel' + id).addClass("fa-check fa-check1")
        }

        showYixuanXiaoqu();
    }

    function showYixuanXiaoqu() {
        var HTML = '';
        var ids = '';
        var names = '';
        for (var i = 0; i < yixuanXiaoqu.length; i++) {
            ids += yixuanXiaoqu[i].id + ',';
            names += yixuanXiaoqu[i].title + ',';
            var item = yixuanXiaoqu[i];
            HTML += '<span class="tag  yixuanxiaoqu-' + item.id + ' ">'
                + item.title
                + '<button type="button" class="close"  onclick="delmid('
                + item.id + ')" >×</button></span>';
        }
        ids = ids.substr(0, ids.length - 1);
        names = names.substr(0, names.length - 1);
        $('#tid_white_list').val(ids);
        $('#tname_white_list').val(names);
        $('.tags').html(HTML);
    }

    //移除已选区小区
    function delmid(id) {
        for (var j = 0; j < yixuanXiaoqu.length; j++) {
            var yitem = yixuanXiaoqu[j];
            if (yitem.id == id) {
                yixuanXiaoqu.splice(j, 1);
            }
        }
        showYixuanXiaoqu();
    }

    $(function () {
        //从js数据中获取地区
        var areasModalBody = '';
        for (var i = 0; i < provs_data.length; i++) {
            console.log(provs_data[i]);
            areasModalBody += "<div class='province'>";
            areasModalBody += "<label class='checkbox-inline' style='margin-left:20px;'>";
            areasModalBody += "<input type='checkbox' class='cityall' style='margin-top:12px;' />";
            areasModalBody += provs_data[i].text;
            areasModalBody += "<span class='citycount' style='color:#ff6600'></span>";
            areasModalBody += "</label>";

            //获取省级下的所有市
            if (citys_data[provs_data[i].value].length > 0) {
                areasModalBody += "<ul>";
                var citys = citys_data[provs_data[i].value];
                for (var j = 0; j < citys.length; j++) {
                    //	alert(JSON.stringify(dists_data[citys[j].value]));

                    areasModalBody += "<li>";
                    areasModalBody += "<label class='checkbox-inline' >";
                    areasModalBody += "<input type='checkbox' class='city' style='margin-top:8px;' city=" + citys[j].text + " />";
                    areasModalBody += citys[j].text;
                    areasModalBody += "</label>";
                    areasModalBody += "</li>";
                }
                areasModalBody += "</ul>";
            }

            areasModalBody += "</div>";
        }
        $("#areas-modal-body").html(areasModalBody);

        $('.province').mouseover(function () {
            $(this).find('ul').show();
        }).mouseout(function () {
            $(this).find('ul').hide();
        });


        $('.cityall').click(function () {
            var checked = $(this).get(0).checked;
            var citys = $(this).parent().parent().find('.city');
            citys.each(function () {
                $(this).get(0).checked = checked;
            });
            var count = 0;
            if (checked) {
                count = $(this).parent().parent().find('.city:checked').length;
            }
            if (count > 0) {
                $(this).next().html("(" + count + ")");
            } else {
                $(this).next().html("");
            }
        });
        $('.city').click(function () {
            var checked = $(this).get(0).checked;
            var cityall = $(this).parent().parent().parent().parent().find('.cityall');

            if (checked) {
                cityall.get(0).checked = true;
            }
            var count = cityall.parent().parent().find('.city:checked').length;
            if (count > 0) {
                cityall.next().html("(" + count + ")");
            } else {
                cityall.next().html("");
            }
        });

        $('#btnSubmitArea').unbind('click').click(function () {
            $('.city:checked').each(function () {
                citystrs += $(this).attr('city') + ";";
            });
            $('.' + current + ' .cityshtml').html(citystrs);
            $('.' + current + ' .citys').val(citystrs);
        })


    });

    var ue = UE.getEditor('content');
    $('#content').data('editor', ue);
    $('#content').parents('form').submit(function () {
        if (ue.queryCommandState('source')) {
            ue.execCommand('source');
        }
    });

    UE.registerUI('uploadImage', function (editor, uiName) {
        return new UE.ui.Button({
            name: '上传图片',
            title: '上传图片',
            cssRules: 'background-position:-380px 0',
            onclick: function () {
                layer.open({
                    id: 'selectImgs',
                    type: 2,
                    title: '批量选择图片',
                    maxmin: true,
                    shadeClose: false,
                    area: ['60%', '70%'],
                    content: '/platform/config/batchUploadImgUeditor'  // iframe的url
                });
            }
        });
    });

    function renderCategoryThird(obj) {
        var index = obj.options[obj.selectedIndex].value;
        var html = "<option value='0'>请选择下级分类</option>";
        if (index == 0) {
            $("#ccate").html(html);
        } else {
            $.ajax({
                url: "/category/manage/getChildByPar",
                data: {"id": index},
                dataType: "json",
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        html += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                    }
                    $("#ccate").html(html);
                }
            })
        }
    }

    function show_type(flag) {
        if (flag == 0) {
            document.getElementById("sendprice").disabled = true;
            document.getElementById("dispatchid").disabled = true;

        } else if (flag == 1) {
            document.getElementById("dispatchid").disabled = true;
            document.getElementById("sendprice").disabled = false;
        } else if (flag == 2) {
            document.getElementById("sendprice").disabled = true;
            document.getElementById("dispatchid").disabled = false;
        }
    }

    $(function () {
        var x = document.getElementById("free_shipping").value;
        show_type(x);
        $(':radio[name=free_shipping]').click(function () {
            var val = $(this).val();
            show_type(val);
        })
    });


    $(function () {
        $("#hasoption").click(function () {
            var obj = $(this);
            if (obj.get(0).checked) {
                $("#tboption").show();
            } else {
                $("#tboption").hide();
            }
        });
    })

    var specCountNum = 1;

    function addSpec() {
        var html = '<div class="panel panel-default spec_item" id="spec_dcx' + specCountNum + '">' +
            '<div class="panel-body"> ' +
            '<input name="spec_id[]" type="hidden" class="form-control spec_id" value="dcx' + specCountNum + '" /> ' +
            '<div class="form-group"> ' +
            '<label class="col-xs-12 col-sm-3 col-md-2 control-label">规格名 </label> ' +
            '<div class="col-sm-9 col-xs-12"> ' +
            '<input name="spec_title[dcx' + specCountNum + ']" type="text" class="form-control spec_title" value="" placeholder="(比如: 颜色)" /> ' +
            '</div> ' +
            '</div> ';

        var secondHtml = '';

        secondHtml = '<div name="listspec" style=""> ' +
            '<div class="form-group"> ' +
            '<label class="col-xs-12 col-sm-3 col-md-2 control-label">规格项</label> ' +
            '<div class="col-sm-9 col-xs-12"> ' +
            '<div id="spec_item_dcx' + specCountNum + '" class="spec_item_items"></div> ' +
            '</div> ' +
            '</div> ' +
            '<div class="form-group"> ' +
            '<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label> ' +
            '<div class="col-sm-9 col-xs-12"> ' +
            '<span> <a id="add-specitem-dcx' + specCountNum + '" specid="dcx' + specCountNum + '" class="btn btn-info add-specitem" onclick="addSpecItem(\'dcx' + specCountNum + '\')"> ' +
            '<i class="fa fa-plus"></i> 添加规格项</a></span> ' +
            '<a class="btn btn-danger" onclick="removeSpec(\'dcx' + specCountNum + '\')"> <i class="fa fa-plus"></i> 删除规格</a> ' +
            '</div> ' +
            '</div> ' +
            '</div> ' +
            '<div name="listspecdel" style="display:none"> ' +
            '<div class="form-group"> ' +
            '<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label> ' +
            '<div class="col-sm-9 col-xs-12"> ' +
            '<a href="javascript:void(0);" class="btn btn-danger" onclick="removeSpec(\'dcx' + specCountNum + '\')"> <i class="fa fa-plus"></i> 删除规格</a> ' +
            '</div> ' +
            '</div> ' +
            '</div> ';

        html += secondHtml + '</div></div>';


        var len = $(".spec_item").length;

        $("#add-spec").html("正在处理...").attr("disabled", "true").toggleClass("btn-primary");
        $("#add-spec").html('<i class="fa fa-plus"></i> 添加规格').removeAttr("disabled").toggleClass("btn-primary");
        $('#specs').append(html);
        var len = $(".add-specitem").length - 1;
        $(".add-specitem:eq(" + len + ")").focus();
        optionchanged = true;

        specCountNum++;
    }

    function removeSpec(specid) {
        if (confirm('确认要删除此规格?')) {
            $("#spec_" + specid).remove();
            optionchanged = true;
        }
        specCountNum--;
    }

    var specItemHiddenId = 1;

    function addSpecItem(specid) {
        var html = '<div class="spec_item_item" style="float:left;margin:0 5px 10px 0;width:250px;">' +
            '<div class="input-group" style="margin:10px 0;">' +
            // '<span class="input-group-addon"> <label class="checkbox-inline" style="margin-top:-20px;"><input type="checkbox" checked="" value="1" onclick="showItem(this)" /></label></span> ' +
            '<input placeholder="*请勿使用+号" data-index=' + specItemHiddenId + ' type="text" class="form-control spec_item_title error" name="spec_item_title_[]" value="" /> ' +
            '<span class="input-group-addon"><a href="javascript:;" onclick="removeSpecItem(this)" title="删除"> <i class="fa fa-times"></i></a></span> ' +
            '</div>' +
            '<div class="input-group "> ' +
            '*如填写将加价<input data-index="' + specItemHiddenId + '" type="text" style="width: 80px;" class="form-control spec_item_price error" value="0" /> ' +
            '<input type="text" value="" class="form-control thumb" id="specItemThumb_' + specItemHiddenId + '" autocomplete="off" /> ' +
            '<span class="input-group-btn"> <button class="btn btn-sm btn-default" type="button" onclick="onSelectImgBtnClick(\'specItemThumb_' + specItemHiddenId + '\',\'dd\');">选择图片</button> </span> ' +
            '</div> ' +
            '<div class="input-group " style="margin-top:.5em;"> ' +
            //'<em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="deleteImage(this)">×</em> '+
            '</div>';
        $("#add-specitem-" + specid).html("正在处理...").attr("disabled", "true");
        $("#add-specitem-" + specid).html('<i class="fa fa-plus"></i> 添加规格项').removeAttr("disabled");
        $('#spec_item_' + specid).append(html);
        var len = $("#spec_" + specid + " .spec_item_title").length - 1;
        $("#spec_" + specid + " .spec_item_title:eq(" + len + ")").focus();
        optionchanged = true;
        specItemHiddenId++;
    }

    function removeSpecItem(obj) {
        $(obj).parent().parent().parent().remove();
    }

    function calc() {
        optionchanged = false;
        var html = '<table class="table table-bordered table-condensed skuTable"><thead><tr class="active">';
        var specs = [];
        if ($('.spec_item').length <= 0) {
            $("#options").html('');
            return;
        }
        $(".spec_item").each(function (i) {
            var _this = $(this);

            var spec = {
                id: _this.find(".spec_id").val(),
                title: _this.find(".spec_title").val()
            };

            var items = [];
            _this.find(".spec_item_item").each(function () {
                var __this = $(this);
                var item = {
                    //id: __this.find(".spec_item_id").val(),
                    id: __this.find(".spec_item_title").attr("data-index"),
                    title: __this.find(".spec_item_title").val(),
                    virtual: __this.find(".spec_item_virtual").val(),
                    specItemHiddesId: __this.find(".spec_item_title").attr("data-index"),
                    price: __this.find(".spec_item_price").val()
                    /* show: __this.find(".spec_item_show").get(0).checked ? "1": "0" */
                }
                items.push(item);
            });
            spec.items = items;
            specs.push(spec);
        });

        specs.sort(function (x, y) {
            if (x.items.length > y.items.length) {
                return 1;
            }
            if (x.items.length < y.items.length) {
                return -1;
            }
        });

        var len = specs.length; //规格数量
        var newlen = 1; // 所有规格项组合数量
        var h = new Array(len);
        var rowspans = new Array(len);
        for (var i = 0; i < len; i++) {
            html += "<th style='width:80px;'>" + specs[i].title + "</th>";
            var itemlen = specs[i].items.length;
            if (itemlen <= 0) {
                itemlen = 1
            }
            ;
            newlen *= itemlen;
            h[i] = new Array(newlen);
            for (var j = 0; j < newlen; j++) {
                h[i][j] = new Array();
            }
            var l = specs[i].items.length;
            rowspans[i] = 1;
            for (j = i + 1; j < len; j++) {
                rowspans[i] *= specs[j].items.length;
            }
        }

        var productType = $("input[name='productType']:checked").val()
        var isziti = $("input[name='isziti']:checked").val();
        var istangshi = $("input[name='istangshi']:checked").val();
        var iswaimai = $("input[name='iswaimai']:checked").val();

        html += '<th class="info" style="width:130px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">库存</div><div class="input-group"><input type="text" class="form-control option_stock_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_stock\');"></a></span></div></div></th>';
        if (productType == 6) {
            if (isziti == 1) {
                html += '<th class="success" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">自提价格</div><div class="input-group"><input readonly="readonly" type="text" class="form-control option_marketprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置"></a></span></div></div></th>';
                html += '<th class="warning" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">自提vip价格</div><div class="input-group"><input type="text" class="form-control option_vipprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_vipprice\');"></a></span></div></div></th>';
            }
            if (istangshi == 1) {
                html += '<th class="success" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">堂食价格</div><div class="input-group"><input readonly="readonly" type="text" class="form-control option_marketprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置"></a></span></div></div></th>';
                html += '<th class="warning" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">堂食vip价格</div><div class="input-group"><input type="text" class="form-control option_vipprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_vipprice\');"></a></span></div></div></th>';
            }
            if (iswaimai == 1) {
                html += '<th class="success" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">外卖价格</div><div class="input-group"><input readonly="readonly" type="text" class="form-control option_marketprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置"></a></span></div></div></th>';
                html += '<th class="warning" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">外卖vip价格</div><div class="input-group"><input type="text" class="form-control option_vipprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_vipprice\');"></a></span></div></div></th>';
            }
        } else {
            html += '<th class="success" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">销售价格</div><div class="input-group"><input readonly="readonly" type="text" class="form-control option_marketprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置"></a></span></div></div></th>';
            html += '<th class="warning" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">市场价格</div><div class="input-group"><input type="text" class="form-control option_productprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_productprice\');"></a></span></div></div></th>';
            html += '<th class="warning" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">vip价格</div><div class="input-group"><input type="text" class="form-control option_vipprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_vipprice\');"></a></span></div></div></th>';
        }
        html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">重量（克）</div><div class="input-group"><input type="text" class="form-control option_weight_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_weight\');"></a></span></div></div></th>';
        html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">门店佣金（元）</div><div class="input-group"><input type="text" class="form-control option_headcommission_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_headcommission\');"></a></span></div></div></th>';
        html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">门店推荐人佣金（元）</div><div class="input-group"><input type="text" class="form-control option_superiorcommission_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_superiorcommission\');"></a></span></div></div></th>';
        html += '</tr></thead>';


        for (var m = 0; m < len; m++) {
            var k = 0,
                kid = 0,
                n = 0;
            var specItemPrice = 0;
            for (var j = 0; j < newlen; j++) {
                var rowspan = rowspans[m];

                h[m][j] = {
                    title: specs[m].items[kid].title,
                    virtual: specs[m].items[kid].virtual,
                    // html: "<td rowspan='" + rowspan + "'>" + specs[m].items[kid].title + "</td>\r\n",
                    html: "<td>" + specs[m].items[kid].title + "</td>\r\n",
                    id: specs[m].items[kid].id,
                    specItemHiddesId: specs[m].items[kid].specItemHiddesId,
                    price: specs[m].items[kid].price
                };
                n++;
                if (n == rowspan) {
                    kid++;
                    if (kid > specs[m].items.length - 1) {
                        kid = 0;
                    }
                    n = 0;
                }
            }
        }

        var hh = '<input name="kw" type="hidden"  value="0"/>';
        for (var i = 0; i < newlen; i++) {

            hh += "<tr>";
            var ids = [];
            var titles = [];
            var virtuals = [];
            var specItemHiddenIds = [];
            var prices = [];
            for (var j = 0; j < len; j++) {
                hh += h[j][i].html;
                ids.push(h[j][i].id);
                titles.push(h[j][i].title);
                specItemHiddenIds.push(h[j][i].specItemHiddesId); // 建立specItem和sku之间的关系
                virtuals.push(h[j][i].virtual);
                prices.push(h[j][i].price);
            }
            ids = ids.join('_');
            titles = titles.join('+');
            specItemHiddenIds = specItemHiddenIds.join('_');

            var zitiprice = Number($("#zitiprice").val())
            for (var priceNum = 0; priceNum < prices.length; priceNum++) {
                zitiprice += Number(prices[priceNum]);
            }

            var tangshiprice = Number($("#tangshiprice").val())
            for (var priceNum = 0; priceNum < prices.length; priceNum++) {
                tangshiprice += Number(prices[priceNum]);
            }

            var waimaiprice = Number($("#waimaiprice").val())
            for (var priceNum = 0; priceNum < prices.length; priceNum++) {
                waimaiprice += Number(prices[priceNum]);
            }

            var tangshivipprice = Number($("#tangshivipprice").val())
            for (var priceNum = 0; priceNum < prices.length; priceNum++) {
                tangshivipprice += Number(prices[priceNum]);
            }

            var waimaivipprice = Number($("#waimaivipprice").val())
            for (var priceNum = 0; priceNum < prices.length; priceNum++) {
                waimaivipprice += Number(prices[priceNum]);
            }

            var zitivipprice = Number($("#zitivipprice").val())
            for (var priceNum = 0; priceNum < prices.length; priceNum++) {
                zitivipprice += Number(prices[priceNum]);
            }
            var marketPrice = Number($("#marketprice").val());
            for (var priceNum = 0; priceNum < prices.length; priceNum++) {
                marketPrice += Number(prices[priceNum]);
            }
            // var offlineprice = Number($("#offlineprice").val());
            // for (var priceNum = 0; priceNum < prices.length; priceNum++) {
            //     offlineprice += Number(prices[priceNum]);
            // }
            var vipprice = Number($("#vipprice").val());
            for (var priceNum = 0; priceNum < prices.length; priceNum++) {
                vipprice += Number(prices[priceNum]);
            }

            var val = {
                id: "",
                title: titles,
                stock: "",
                productprice: "",
                marketprice: marketPrice,
                // offlineprice: offlineprice,
                vipprice: vipprice,
                zitiprice: zitiprice,
                tangshiprice: tangshiprice,
                waimaiprice: waimaiprice,
                tangshivipprice: tangshivipprice,
                waimaivipprice: waimaivipprice,
                zitivipprice: zitivipprice,
                weight: "",
                superiorcommission: "",
                headcommission: "",
                virtual: virtuals,
                specItemHiddenIds: specItemHiddenIds
            };
            if ($(".option_id_" + ids).length > 0) {
                val = {
                    id: $(".option_id_" + ids + ":eq(0)").val(),
                    title: titles,
                    specItemHiddenIds: specItemHiddenIds,
                    stock: $(".option_stock_" + ids + ":eq(0)").val(),
                    productprice: $(".option_productprice_" + ids + ":eq(0)").val(),
                    marketprice: marketPrice,
                    // offlineprice: offlineprice,
                    //vipprice: $(".option_vipprice_" + ids + ":eq(0)").val(),
                    vipprice: vipprice,
                    zitiprice: zitiprice,
                    tangshiprice: tangshiprice,
                    waimaiprice: waimaiprice,
                    tangshivipprice: tangshivipprice,
                    waimaivipprice: waimaivipprice,
                    zitivipprice: zitivipprice,
                    weight: $(".option_weight_" + ids + ":eq(0)").val(),
                    superiorcommission: $(".option_superiorcommission_" + ids + ":eq(0)").val(),
                    headcommission: $(".option_headcommission_" + ids + ":eq(0)").val(),
                    headtype: $(".option_headtype_" + ids + ":eq(0)").val(),
                    superiortype: $(".option_superiortype_" + ids + ":eq(0)").val(),
                    virtual: virtuals
                }
            }
            hh += '<td class="info">' + '<input name="option_stock_' + ids + '[]" type="number" min="0" class="form-control option_stock option_stock_' + ids + '" value="' + (val.stock == 'undefined' ? '' : val.stock) + '"/></td>';
            hh += '<input name="option_id_' + ids + '[]" type="hidden" class="form-control option_id option_id_' + ids + '" value="' + (val.id == 'undefined' ? '' : val.id) + '"/>';
            hh += '<input name="option_ids[]" type="hidden" class="form-control option_ids option_ids_' + ids + '" value="' + ids + '"/>';
            hh += '<input type="hidden" class="form-control option_title option_title_' + ids + '" value="' + (val.title == 'undefined' ? '' : val.title) + '"/></td>';
            hh += '<input type="hidden" class="form-control option_specItemHiddenId" value="' + (val.specItemHiddenIds == 'undefined' ? '' : val.specItemHiddenIds) + '"/></td>';
            /* hh += '<input name="option_virtual_' + ids + '[]"type="hidden" class="form-control option_title option_title_' + ids + '" value="' + (val.virtual == 'undefined' ? '': val.virtual) + '"/></td>'; */
            hh += '</td>';


            if (productType == 6) {
                if (isziti == 1) {
                    hh += '<td class="success"><input readonly="readonly" name="option_marketprice_' + ids + '[]" type="number" min="0" class="form-control option_zitiprice option_marketprice_' + ids + '" value="' + (val.zitiprice == 'undefined' ? '' : val.zitiprice) + '"/></td>';
                    hh += '<td class="warning"><input name="option_vipprice_' + ids + '[]" type="number" min="0" class="form-control option_zitivipprice option_vipprice_' + ids + '" " value="' + (val.zitivipprice == 'undefined' ? '' : val.zitivipprice) + '"/></td>';
                }
                if (istangshi == 1) {
                    hh += '<td class="success"><input readonly="readonly" name="option_marketprice_' + ids + '[]" type="number" min="0" class="form-control option_tangshiprice option_marketprice_' + ids + '" value="' + (val.tangshiprice == 'undefined' ? '' : val.tangshiprice) + '"/></td>';
                    hh += '<td class="warning"><input name="option_vipprice_' + ids + '[]" type="number" min="0" class="form-control option_tangshivipprice option_vipprice_' + ids + '" " value="' + (val.tangshivipprice == 'undefined' ? '' : val.tangshivipprice) + '"/></td>';
                }
                if (iswaimai == 1) {
                    hh += '<td class="success"><input readonly="readonly" name="option_marketprice_' + ids + '[]" type="number" min="0" class="form-control option_waimaiprice option_marketprice_' + ids + '" value="' + (val.waimaiprice == 'undefined' ? '' : val.waimaiprice) + '"/></td>';
                    hh += '<td class="warning"><input name="option_vipprice_' + ids + '[]" type="number" min="0" class="form-control option_waimaivipprice option_vipprice_' + ids + '" " value="' + (val.waimaivipprice == 'undefined' ? '' : val.waimaivipprice) + '"/></td>';
                }
            } else {
                hh += '<td class="success"><input readonly="readonly" name="option_marketprice_' + ids + '[]" type="number" min="0" class="form-control option_marketprice option_marketprice_' + ids + '" value="' + (val.marketprice == 'undefined' ? '' : val.marketprice) + '"/></td>';
                hh += '<td class="warning"><input name="option_productprice_' + ids + '[]" type="number" min="0" class="form-control option_productprice option_productprice_' + ids + '" " value="' + (val.productprice == 'undefined' ? '' : val.productprice) + '"/></td>';
                hh += '<td class="warning"><input name="option_vipprice_' + ids + '[]" type="number" min="0" class="form-control option_vipprice option_vipprice_' + ids + '" " value="' + (val.vipprice == 'undefined' ? '' : val.vipprice) + '"/></td>';
                // hh += '<td class="warning"><input name="option_offlineprice_' + ids + '[]" type="number" min="0" class="form-control option_offlineprice option_offlineprice_' + ids + '" " value="' + (val.offlineprice == 'undefined' ? '' : val.offlineprice) + '"/></td>';
            }


            hh += '<td class="info"><input name="option_weight_' + ids + '[]" type="number" min="0" class="form-control option_weight option_weight_' + ids + '" " value="' + (val.weight == 'undefined' ? '' : val.weight) + '"/></td>';
            hh += '<td class="info" style="width:150px;"><div class=""><div class="input-group"><input name="option_headcommission_' + ids + '[]" type="number" min="0" class="form-control option_headcommission option_headcommission_' + ids + '" " value="' + (val.headcommission == 'undefined' ? '' : val.headcommission) + '"/><span class="input-group-addon" style="padding:0px;"><select  name="option_headtype_' + ids + '[]" type="text" class="option_headtype option_headtype_' + ids + '"  style="border-style:solid; border-color:#FFF"  ><option value="0"  >元</option><option value="1"  >%</option></select></span></div></div></td>';
            hh += '<td class="info" style="width:150px;"><div class=""><div class="input-group"><input name="option_superiorcommission_' + ids + '[]" type="number" min="0" class="form-control option_superiorcommission option_superiorcommission_' + ids + '" " value="' + (val.superiorcommission == 'undefined' ? '' : val.superiorcommission) + '"/><span class="input-group-addon" style="padding:0px;"><select  name="option_superiortype_' + ids + '[]" type="text" class="option_superiortype option_superiortype_' + ids + '"  style="border-style:solid; border-color:#FFF"  ><option value="0"  >元</option><option value="1">%</option></select></span></div></div></td>';
            hh += "</tr>";
        }
        html += hh;
        html += "</table>";
        $("#options").html(html);
    }

    function setCol(cls) {
        $("." + cls).val($("." + cls + "_all").val());
    }

    $("#isSpellgroup").click(function () {
        var isSpellgroup = $("#isSpellgroup").prop("checked");
        if (isSpellgroup) {
            $('#spellgroupnum').attr("readonly", false);
        } else {
            $('#spellgroupnum').attr("readonly", true);
        }
    });

    var optionchanged = false;

    function saveProduct() {
        var specs = [];
        // 组装规格和规格属性
        if ($('.spec_item').length > 0) {
            $(".spec_item").each(function (i) {
                var specItems = [];
                var _this = $(this);
                $(_this.find(".spec_item_item")).each(function (i) {
                    var _specItemItem = $(this);
                    var specItem = {
                        title: _specItemItem.find('.spec_item_title').val(),
                        thumb: _specItemItem.find('.thumb').val(),
                        specItemHiddenId: _specItemItem.find('.spec_item_title').attr('data-index'),
                        price: _specItemItem.find('.spec_item_price').val()
                        /* thumb:_this.find */
                    }
                    specItems.push(specItem);
                })
                var spec = {
                    title: _this.find(".spec_title").val(),
                    specItemList: specItems
                };
                specs.push(spec); // 设置规格
            })
            /* console.info(specs); */
        }

        // 遍历sku，组装sku
        var skuList = [];
        $(".skuTable tbody tr").each(function () {
            var _this = $(this);
            var sku = {
                id: _this.find(".option_id").val(),
                title: _this.find(".option_title").val(),
                specItemHiddenId: _this.find(".option_specItemHiddenId").val(),
                productprice: _this.find(".option_productprice").val(),
                marketprice: _this.find(".option_marketprice").val(),
                // offlineprice: _this.find(".option_offlineprice").val(),
                vipprice: _this.find(".option_vipprice").val(),
                zitiprice: _this.find(".option_zitiprice").val(),
                tangshiprice: _this.find(".option_tangshiprice").val(),
                waimaiprice: _this.find(".option_waimaiprice").val(),
                tangshivipprice: _this.find(".option_tangshivipprice").val(),
                waimaivipprice: _this.find(".option_waimaivipprice").val(),
                zitivipprice: _this.find(".option_zitivipprice").val(),
                stock: _this.find(".option_stock").val(),
                weight: _this.find(".option_weight").val(),
                headcommission: _this.find(".option_headcommission").val(),
                headtype: _this.find(".option_headtype").val(),
                superiorcommission: _this.find(".option_superiorcommission").val(),
                superiortype: _this.find(".option_superiortype").val()

            }
            skuList.push(sku);
        })
        console.info(skuList);
        console.info(specs);

        var productType = $("input[name='productType']:checked").val();

        if ($("#title").val() == '' || $("#title").val() == undefined) {
            layer.alert("请输入商品名称!", {icon: 5});
            return false;
        }

        // if ($("#manudate").val() == '' || $("#manudate").val() == undefined) {
        //     layer.alert("请选择商品生产日期!", {icon: 5});
        //     return false;
        // }

        // if ($("#guarantday").val() == '' || $("#guarantday").val() == undefined) {
        //     layer.alert("请填写商品保质期!", {icon: 5});
        //     return false;
        // }

        // if (($("#liansuoid").val() == '' || $("#liansuoid").val() == undefined || $("#liansuoid").val() == 0) && ($("#teamId").val() == '' || $("#teamId").val() == undefined)) {
        //     layer.alert("请选择门店!", {icon: 5});
        //     return false;
        // }

        if ($.trim($(':input[name="thumb"]').val()) == '') {
            layer.alert("请上传缩略图!", {icon: 5});
            return false;
        }

        var productprice = $("#productprice").val();
        // var offlineprice = $("#offlineprice").val();
        var zitiprice = $("#zitiprice").val()
        var tangshiprice = $("#tangshiprice").val()
        var waimaiprice = $("#waimaiprice").val()
        var tangshivipprice = $("#tangshivipprice").val()
        var waimaivipprice = $("#waimaivipprice").val()
        var zitivipprice = $("#zitivipprice").val()
        var waimaiproductprice = $("#waimaiproductprice").val()

        var isziti = $("input[name='isziti']:checked").val();
        var istangshi = $("input[name='istangshi']:checked").val();
        var iswaimai = $("input[name='iswaimai']:checked").val();

        if (productType != 6) {
            if ($("#marketprice").val() == '' || $("#marketprice").val() == undefined) {
                layer.alert("请输入商品现价!", {icon: 5});
                return false;
            }
            // if ($("#offlineprice").val() == '' || $("#offlineprice").val() == undefined) {
            //     layer.alert("请输入线下价格!", {icon: 5});
            //     return false;
            // }
            if ($("#productprice").val() == '' || $("#productprice").val() == undefined) {
                layer.alert("请输入商品原价!", {icon: 5});
                return false;
            }
            if ($("#costprice").val() == '' || $("#costprice").val() == undefined) {
                layer.alert("请输入商品成本价!", {icon: 5});
                return false;
            }
            // if ($("#vipprice").val() == '' || $("#vipprice").val() == undefined) {
            //     layer.alert("请输入商品vip价!", {icon: 5});
            //     return false;
            // }
        } else {
            // if (isziti == 1) {
            //     if (zitiprice == '' || zitiprice == undefined) {
            //         layer.alert("请输入自提价!", {icon: 5});
            //         return false;
            //     }
            //     if (zitivipprice == '' || zitivipprice == undefined) {
            //         layer.alert("请输入自提vip价!", {icon: 5});
            //         return false;
            //     }
            // }
            // if (istangshi == 1) {
            //     if (tangshiprice == '' || tangshiprice == undefined) {
            //         layer.alert("请输入堂食价!", {icon: 5});
            //         return false;
            //     }
            //     if (tangshivipprice == '' || tangshivipprice == undefined) {
            //         layer.alert("请输入堂食vip价!", {icon: 5});
            //         return false;
            //     }
            // }
            // if (iswaimai == 1) {
            //     if (waimaiproductprice == '' || waimaiproductprice == undefined) {
            //         layer.alert("请输入外卖原价!", {icon: 5});
            //         return false;
            //     } else {
            //         productprice = waimaiproductprice;
            //     }
            //     if (waimaiprice == '' || waimaiprice == undefined) {
            //         layer.alert("请输入外卖现价!", {icon: 5});
            //         return false;
            //     }
            //     if (waimaivipprice == '' || waimaivipprice == undefined) {
            //         layer.alert("请输入外卖vip价!", {icon: 5});
            //         return false;
            //     }
            // }
        }

        // if ($("#weight").val() == '' || $("#weight").val() == undefined) {
        //     layer.alert("请输入商品重量!", {icon: 5});
        //     return false;
        // }
        // if ($("#total").val() == '' || $("#total").val() == undefined) {
        //     layer.alert("请输入商品库存!", {icon: 5});
        //     return false;
        // }

        var full = true;
        // full = checkoption();
        if (!full) {
            return false;
        }
        if (optionchanged) {
            layer.alert("规格数据有变动，请重新点击 [刷新规格项目表] 按钮!", {icon: 5});
            return false;
        }
        var displayorder = $("#displayorder").val();
        if (displayorder > 2147483647) {
            layer.msg("排序值过大");
            return;
        }
        var title = $("#title").val();
        var shortTitle = $("#shortTitle").val();
        var goodscode = $("#goodscode").val();
        var specTitle = $("#specTitle").val();
        var pinyinkeyword = $("#pinyinkeyword").val();
        var pcate = $("#pcate").val();
        var ccate = $("#ccate").val();
        var supplierId = $("#supplierId").val();
        var liansuoid = $("#teamId").val() != null && $("#teamId").val() != '' ? $("#teamId").val() : $("#liansuoid").val();
        var unit = $("#unit").val();
        var isrecommand = $("input[name='isrecommand']:checked").val();
        var isTeamBuy = $("input[name='isTeamBuy']:checked").val();
        var isKuaidi = $("input[name='isKuaidi']:checked").val();
        var isnew = $("input[name='isnew']:checked").val();
        var ishot = $("input[name='ishot']:checked").val();
        var isdiscount = $("input[name='isdiscount']:checked").val();
        var istime = $("input[name='istime']:checked").val();
        var ismiaosha = $("input[name='ismiaosha']:checked").val();
        var islimited = $("input[name='islimited']:checked").val();

        var iszhicai = $("input[name='iszhicai']:checked").val();
        var ismao = $("input[name='ismao']:checked").val();
        var isfanchang = $("input[name='isfanchang']:checked").val();
        /* var isgerida = $("input[name='isgerida']:checked").val(); */
        var isfashi = $("input[name='isfashi']:checked").val();
        var iszhutihuakuang = $("input[name='iszhutihuakuang']:checked").val();
        var manudate = $("#manudate").val();
        var guarantday = $("#guarantday").val();

        var selfvalue = $("#selfvalue").val();
        var timestart = $("#timestart").val();
        var timeend = $("#timeend").val();
        // if (timestart == '' || timestart == undefined || timeend == '' || timeend == undefined) {
        //     layer.msg("请输入商品限卖时间", {icon: 5});
        //     return false;
        // }
        var thumb = $("#thumb").val();
        var thumbSquare = $("#thumbSquare").val();
        var thumbUrlBak = $("#thumbUrlBak").val();
        var videourl = $("#videourl").val();
        var thumbUrl = $("#thumbUrl").val();
        var marketprice = $("#marketprice").val();
        var offlineprice = $("#offlineprice").val();

        var startLimit = $("#startLimit").val();

        var costprice = $("#costprice").val();
        var vipprice = $("#vipprice").val();
        var weight = $("#weight").val();
        var total = $("#total").val();
        var maxbuy = $("#maxbuy").val();
        var usermaxbuy = $("#usermaxbuy").val();

        var sales = $("#sales").val();
        var viewcount = $("#viewcount").val();
        var credit = $("#credit").val();
        var status = $('input[name="status"]:checked').val();
        if (status == 2) {
            var upStartTime = $("#upStartTime").val();
            var upEndTime = $("#upEndTime").val();
        }
        var isgongyi = $('input[name="isgongyi"]:checked').val();
        if (isgongyi == 1) {
            var gongyiprice = $("#gongyiprice").val();
        }
        var areas = $("#selectedareas").val();
        var showsupply = $('input[name="showsupply"]:checked').val();
        var uncancelable = $('input[name="uncancelable"]:checked').val();
        var description = UE.getEditor('content').getContent();
        var tihuoday = $("#tihuoday").val();
        var freeShipping = $('input[name="free_shipping"]:checked').val();
        var sendprice = $("#sendprice").val(); // 独立邮费
        var dispatchid = $("#dispatchid").val(); // 邮费模板

        var isFxCommission = 0; //是否开启门店佣金
        if ($('#is_fx_commission').is(':checked')) {
            isFxCommission = 1;
        }
        var headcommission = $("#headcommission").val();  //门店佣金设置
        var headtype = $("#headtype").val();
        var clerkercommission = $("#clerkercommission").val();  //门店佣金设置
        var clerkertype = $("#clerkertype").val();
        var superiorcommission = $("#superiorcommission").val();
        var superiortype = $("#superiortype").val();
        var proddes = $("#proddes").val();
        var productid = $("#productid").val();
        var usercommission = $("#usercommission").val();
        var usertype = $("#usertype").val();
        var superusercommission = $("#superusercommission").val();
        var superusertype = $("#superusertype").val();
        var isSpellgroup = $("input[name='isSpellgroup']:checked").val();
        var spellgroupnum = $("#spellgroupnum").val();
        var ispresell = $("input[name='ispresell']:checked").val();
        var discountStatus = $("input[name='discountStatus']:checked").val();
        var discount = $("#discount").val();
        var consumptionIntegral =  $("#consumptionIntegral").val();
        var data = {
            "id": productid,
            "displayorder": displayorder,
            "goodscode": goodscode,
            "specTitle": specTitle,
            "pinyinkeyword": pinyinkeyword,
            "pcate": pcate,
            "ccate": ccate,
            "supplierId": supplierId,
            "isrecommand": isrecommand,
            "title": title,
            "shortTitle": shortTitle,
            "unit": unit,
            "selfvalue": selfvalue,
            "timestart": timestart,
            "timeend": timeend,
            "thumb": thumb,
            "thumbSquare": thumbSquare,
            "thumbUrlBak": thumbUrlBak,
            "videourl": videourl,
            "thumbUrl": thumbUrl,
            "marketprice": marketprice,
            "offlineprice": offlineprice,
            "startLimit": startLimit,
            "productprice": productprice,
            "costprice": costprice,
            "vipprice": vipprice,
            "weight": weight,
            "total": total,
            "maxbuy": maxbuy,
            "usermaxbuy": usermaxbuy,
            "sales": sales,
            "status": status,
            "upStartTime": upStartTime,
            "upEndTime": upEndTime,
            "isgongyi": isgongyi,
            "viewcount": viewcount,
            "gongyiprice": gongyiprice,
            "showsupply": showsupply,
            "uncancelable": uncancelable,
            "areas": areas,
            "description": description,
            "freeShipping": freeShipping,
            "sendprice": sendprice,
            "dispatchid": dispatchid,
            "isFxCommission": isFxCommission,
            "headcommission": headcommission,
            "headtype": headtype,
            "clerkercommission": clerkercommission,
            "clerkertype": clerkertype,
            "superiorcommission": superiorcommission,
            "superiortype": superiortype,
            "tihuoday": tihuoday,
            "guarantday": guarantday,
            "manudate": manudate,
            "proddes": proddes,
            "credit": credit,
            "liansuoid": liansuoid,
            "usertype": usertype,
            "usercommission": usercommission,
            "superusertype": superusertype,
            "superusercommission": superusercommission,
            "isSpellgroup": isSpellgroup,
            "spellgroupnum": spellgroupnum,
            "ispresell": ispresell,
            "productType": productType,
            "zitiprice": zitiprice,
            "tangshiprice": tangshiprice,
            "waimaiprice": waimaiprice,
            "tangshivipprice": tangshivipprice,
            "waimaivipprice": waimaivipprice,
            "zitivipprice": zitivipprice,
            "discountStatus": discountStatus,
            "discount": discount,
            "consumptionIntegral":consumptionIntegral
        };

        data.specList = specs;
        data.skuList = skuList;
        if (isziti == 1) {
            data.isziti = 1
        } else {
            data.isziti = 0
        }
        ;
        if (istangshi == 1) {
            data.istangshi = 1
        } else {
            data.istangshi = 0
        }
        ;
        if (iswaimai == 1) {
            data.iswaimai = 1
        } else {
            data.iswaimai = 0
        }
        ;
        if (isrecommand == 1) data.isrecommand = 1;
        if (isnew == 1) data.isnew = 1;
        if (isTeamBuy == 1) data.isTeamBuy = 1;
        if (ishot == 1) data.ishot = 1;
        if (isKuaidi == 1) data.isKuaidi = 1;
        if (isdiscount == 1) data.isdiscount = 1;
        if (ismiaosha == 1) data.ismiaosha = 1;
        if (islimited == 1) data.islimited = 1;
        if (istime == 1) data.istime = 1;
        if (iszhicai == 1) data.iszhicai = 1;
        if (ismao == 1) data.ismao = 1;
        if (isfanchang == 1) data.isfanchang = 1;
        /* if (isgerida == 1) data.isgerida=1; */
        if (isfashi == 1) data.isfashi = 1;
        if (iszhutihuakuang == 1) data.iszhutihuakuang = 1;

        var hasoption = $("input[name='hasoption']:checked").val();
        var secondSpec = 0;
        if (hasoption == 1) data.hasoption = 1;
        if (secondSpec == 1) data.hasoptionsbuy = 1;

        $.ajax({
            url: '/reservationProduct/manage/save',
            contentType: "application/json",
            dataType: "json",
            type: 'POST',
            data: JSON.stringify(data),
            success: function (result) {
                if (result.code == 0) {
                   // $("#productid").val(result.msg);
                    layer.alert("保存成功", {icon: 6});
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);
                } else {
                    if (result.msg == '' || result.msg == null) {
                        layer.alert("保存失败，请联系管理员", {icon: 5});
                    } else {
                        layer.alert(result.msg, {icon: 5});
                    }

                }
            }
        })
    }

    function onSelectImgBtnClick(inputId, imgId) {
        layer.open({
            id: 'selectImg',
            type: 2,
            title: '选择图片',
            maxmin: true,
            shadeClose: false,
            area: ['60%', '70%'],
            content: '/platform/config/selectImg/' + inputId + "/" + imgId // iframe的url
        });
    }

    function onSelectVideoBtnClick(inputId, imgId) {
        layer.open({
            id: 'selectImg',
            type: 2,
            title: '选择视频',
            maxmin: true,
            shadeClose: false,
            area: ['60%', '70%'],
            content: '/platform/config/selectVideo/' + inputId + "/" + imgId // iframe的url
        });
    }

    /**
     * 加载图片URL
     * @param inputId
     * @param imgId
     * @param url
     */
    function loadImgUrl(inputId, imgId, url) {
        $('#' + inputId + '').val(url);
        $('#' + imgId + '').attr('src', url);
    }

    // 批量上传图片
    function selectImgs(domId) {
        layer.open({
            id: 'selectImgs',
            type: 2,
            title: '批量选择图片',
            maxmin: true,
            shadeClose: false,
            area: ['60%', '70%'],
            content: '/platform/config/batchUploadImg/' + domId // iframe的url
        });
    }

    function loadImgsInfo(domId, result) {
        if (!result || result.length < 1) {
            layer.msg(result.msg, {icon: 7});
            return;
        }
        $('#thumbUrl').val(result.join(","));
    }

    // 加载图片进ueditor中
    function loadImgsToUeditor(result) {
        if (!result || result.length < 1) {
            layer.msg(result.msg, {icon: 7});
            return;
        }
        console.info(result);
        /* var imgUrlArray = result.split(","); */
        let editor = UE.getEditor('content');
        for (var i = 0; i < result.length; i++) {
            var imgUrl = result[i];
            editor.execCommand('inserthtml', `<img src=${imgUrl}>`);
        }
    }

    function reset() {
        $("#productid").val("");
        layer.alert("重置成功!您可添加新的商品!", {icon: 6});
    }

    function changeValue2() {
        var marketprice = $("#marketprice").val();
        var usercommission = $("#usercommission").val();
        var superiortype = $("#usertype option:selected").val();
        if (superiortype == 1) {
            $("#usercommission").val(marketprice * (usercommission / 100));
            $("#usertype option:first").prop("selected", 'selected');
        }
    }

    function changeValue3() {
        var marketprice = $("#marketprice").val();
        var superusercommission = $("#superusercommission").val();
        var superiortype = $("#superusertype option:selected").val();
        if (superiortype == 1) {
            $("#superusercommission").val(marketprice * (superusercommission / 100));
            $("#superusertype option:first").prop("selected", 'selected');
        }
    }

    function changeVlue() {
        var flag = $("input[name='isKuaidi']:checked").val();
        if (flag == 1) {
            var citystrs = "北京市;天津市;石家庄市;唐山市;秦皇岛市;邯郸市;邢台市;保定市;张家口市;承德市;沧州市;廊坊市;衡水市;太原市;大同市;阳泉市;长治市;晋城市;朔州市;晋中市;运城市;忻州市;临汾市;吕梁市;呼和浩特市;包头市;乌海市;赤峰市;通辽市;鄂尔多斯市;呼伦贝尔市;巴彦淖尔市;乌兰察布市;兴安盟;锡林郭勒盟;阿拉善盟;沈阳市;大连市;鞍山市;抚顺市;本溪市;丹东市;锦州市;营口市;阜新市;辽阳市;盘锦市;铁岭市;朝阳市;葫芦岛市;长春市;吉林市;四平市;辽源市;通化市;白山市;松原市;白城市;延边朝鲜族自治州;哈尔滨市;齐齐哈尔市;鸡西市;鹤岗市;双鸭山市;大庆市;伊春市;佳木斯市;七台河市;牡丹江市;黑河市;绥化市;大兴安岭地区;上海市;南京市;无锡市;徐州市;常州市;苏州市;南通市;连云港市;淮安市;盐城市;扬州市;镇江市;泰州市;宿迁市;杭州市;宁波市;温州市;嘉兴市;湖州市;绍兴市;金华市;衢州市;舟山市;台州市;丽水市;合肥市;芜湖市;蚌埠市;淮南市;马鞍山市;淮北市;铜陵市;安庆市;黄山市;滁州市;阜阳市;宿州市;六安市;亳州市;池州市;宣城市;福州市;厦门市;莆田市;三明市;泉州市;漳州市;南平市;龙岩市;宁德市;南昌市;景德镇市;萍乡市;九江市;新余市;鹰潭市;赣州市;吉安市;宜春市;抚州市;上饶市;济南市;青岛市;淄博市;枣庄市;东营市;烟台市;潍坊市;济宁市;泰安市;威海市;日照市;莱芜市;临沂市;德州市;聊城市;滨州市;菏泽市;郑州市;开封市;洛阳市;平顶山市;安阳市;鹤壁市;新乡市;焦作市;濮阳市;许昌市;漯河市;三门峡市;南阳市;商丘市;信阳市;周口市;驻马店市;武汉市;黄石市;十堰市;宜昌市;襄阳市;鄂州市;荆门市;孝感市;荆州市;黄冈市;咸宁市;随州市;恩施土家族苗族自治州;仙桃市;潜江市;天门市;神农架林区;长沙市;浏阳市;株洲市;湘潭市;衡阳市;邵阳市;岳阳市;常德市;张家界市;益阳市;郴州市;永州市;怀化市;娄底市;湘西土家族苗族自治州;广州市;韶关市;深圳市;珠海市;汕头市;佛山市;江门市;湛江市;茂名市;肇庆市;惠州市;梅州市;汕尾市;河源市;阳江市;清远市;东莞市;中山市;潮州市;揭阳市;云浮市;南宁市;柳州市;桂林市;梧州市;北海市;防城港市;钦州市;贵港市;玉林市;百色市;贺州市;河池市;来宾市;崇左市;海口市;三亚市;五指山市;琼海市;儋州市;文昌市;万宁市;东方市;定安县;屯昌县;澄迈县;临高县;白沙黎族自治县;昌江黎族自治县;乐东黎族自治县;陵水黎族自治县;保亭黎族苗族自治县;琼中黎族苗族自治县;西沙群岛;南沙群岛;中沙群岛的岛礁及其海域;重庆市;成都市;自贡市;攀枝花市;泸州市;德阳市;绵阳市;广元市;遂宁市;内江市;乐山市;南充市;眉山市;宜宾市;广安市;达州市;雅安市;巴中市;资阳市;阿坝藏族羌族自治州;甘孜藏族自治州;凉山彝族自治州;贵阳市;六盘水市;遵义市;安顺市;铜仁地区;黔西南布依族苗族自治州;毕节地区;黔东南苗族侗族自治州;黔南布依族苗族自治州;昆明市;曲靖市;玉溪市;保山市;昭通市;丽江市;普洱市;临沧市;楚雄彝族自治州;红河哈尼族彝族自治州;文山壮族苗族自治州;西双版纳傣族自治州;大理白族自治州;德宏傣族景颇族自治州;怒江傈僳族自治州;迪庆藏族自治州;拉萨市;昌都地区;山南地区;日喀则地区;那曲地区;阿里地区;林芝地区;西安市;铜川市;宝鸡市;咸阳市;渭南市;延安市;汉中市;榆林市;安康市;商洛市;兰州市;嘉峪关市;金昌市;白银市;天水市;武威市;张掖市;平凉市;酒泉市;庆阳市;定西市;陇南市;临夏回族自治州;甘南藏族自治州;西宁市;海东地区;海北藏族自治州;黄南藏族自治州;海南藏族自治州;果洛藏族自治州;玉树藏族自治州;海西蒙古族藏族自治州;银川市;石嘴山市;吴忠市;固原市;中卫市;乌鲁木齐市;克拉玛依市;吐鲁番地区;哈密地区;昌吉回族自治州;博尔塔拉蒙古自治州;巴音郭楞蒙古自治州;阿克苏地区;克孜勒苏柯尔克孜自治州;喀什地区;和田地区;伊犁哈萨克自治州;塔城地区;阿勒泰地区;石河子市;阿拉尔市;图木舒克市;五家渠市;台北市;高雄市;台南市;台中市;基隆市;新竹市;嘉义市;地级县市;香港岛;九龙;新界;澳门半岛;离岛;海外;"
            $('#areas').html(citystrs);
            $('#selectedareas').val(citystrs);
        } else {
            $('#areas').html("北京市;天津市;石家庄市;唐山市;秦皇岛市;邯郸市;邢台市;保定市;张家口市;承德市;沧州市;廊坊市;衡水市;太原市;大同市;阳泉市;长治市;晋城市;朔州市;晋中市;运城市;忻州市;临汾市;吕梁市;呼和浩特市;包头市;乌海市;赤峰市;通辽市;鄂尔多斯市;呼伦贝尔市;巴彦淖尔市;乌兰察布市;兴安盟;锡林郭勒盟;阿拉善盟;沈阳市;大连市;鞍山市;抚顺市;本溪市;丹东市;锦州市;营口市;阜新市;辽阳市;盘锦市;铁岭市;朝阳市;葫芦岛市;长春市;吉林市;四平市;辽源市;通化市;白山市;松原市;白城市;延边朝鲜族自治州;哈尔滨市;齐齐哈尔市;鸡西市;鹤岗市;双鸭山市;大庆市;伊春市;佳木斯市;七台河市;牡丹江市;黑河市;绥化市;大兴安岭地区;上海市;南京市;无锡市;徐州市;常州市;苏州市;南通市;连云港市;淮安市;盐城市;扬州市;镇江市;泰州市;宿迁市;杭州市;宁波市;温州市;嘉兴市;湖州市;绍兴市;金华市;衢州市;舟山市;台州市;丽水市;合肥市;芜湖市;蚌埠市;淮南市;马鞍山市;淮北市;铜陵市;安庆市;黄山市;滁州市;阜阳市;宿州市;六安市;亳州市;池州市;宣城市;福州市;厦门市;莆田市;三明市;泉州市;漳州市;南平市;龙岩市;宁德市;南昌市;景德镇市;萍乡市;九江市;新余市;鹰潭市;赣州市;吉安市;宜春市;抚州市;上饶市;济南市;青岛市;淄博市;枣庄市;东营市;烟台市;潍坊市;济宁市;泰安市;威海市;日照市;莱芜市;临沂市;德州市;聊城市;滨州市;菏泽市;郑州市;开封市;洛阳市;平顶山市;安阳市;鹤壁市;新乡市;焦作市;濮阳市;许昌市;漯河市;三门峡市;南阳市;商丘市;信阳市;周口市;驻马店市;武汉市;黄石市;十堰市;宜昌市;襄阳市;鄂州市;荆门市;孝感市;荆州市;黄冈市;咸宁市;随州市;恩施土家族苗族自治州;仙桃市;潜江市;天门市;神农架林区;长沙市;浏阳市;株洲市;湘潭市;衡阳市;邵阳市;岳阳市;常德市;张家界市;益阳市;郴州市;永州市;怀化市;娄底市;湘西土家族苗族自治州;广州市;韶关市;深圳市;珠海市;汕头市;佛山市;江门市;湛江市;茂名市;肇庆市;惠州市;梅州市;汕尾市;河源市;阳江市;清远市;东莞市;中山市;潮州市;揭阳市;云浮市;南宁市;柳州市;桂林市;梧州市;北海市;防城港市;钦州市;贵港市;玉林市;百色市;贺州市;河池市;来宾市;崇左市;海口市;三亚市;五指山市;琼海市;儋州市;文昌市;万宁市;东方市;定安县;屯昌县;澄迈县;临高县;白沙黎族自治县;昌江黎族自治县;乐东黎族自治县;陵水黎族自治县;保亭黎族苗族自治县;琼中黎族苗族自治县;西沙群岛;南沙群岛;中沙群岛的岛礁及其海域;重庆市;成都市;自贡市;攀枝花市;泸州市;德阳市;绵阳市;广元市;遂宁市;内江市;乐山市;南充市;眉山市;宜宾市;广安市;达州市;雅安市;巴中市;资阳市;阿坝藏族羌族自治州;甘孜藏族自治州;凉山彝族自治州;贵阳市;六盘水市;遵义市;安顺市;铜仁地区;黔西南布依族苗族自治州;毕节地区;黔东南苗族侗族自治州;黔南布依族苗族自治州;昆明市;曲靖市;玉溪市;保山市;昭通市;丽江市;普洱市;临沧市;楚雄彝族自治州;红河哈尼族彝族自治州;文山壮族苗族自治州;西双版纳傣族自治州;大理白族自治州;德宏傣族景颇族自治州;怒江傈僳族自治州;迪庆藏族自治州;拉萨市;昌都地区;山南地区;日喀则地区;那曲地区;阿里地区;林芝地区;西安市;铜川市;宝鸡市;咸阳市;渭南市;延安市;汉中市;榆林市;安康市;商洛市;兰州市;嘉峪关市;金昌市;白银市;天水市;武威市;张掖市;平凉市;酒泉市;庆阳市;定西市;陇南市;临夏回族自治州;甘南藏族自治州;西宁市;海东地区;海北藏族自治州;黄南藏族自治州;海南藏族自治州;果洛藏族自治州;玉树藏族自治州;海西蒙古族藏族自治州;银川市;石嘴山市;吴忠市;固原市;中卫市;乌鲁木齐市;克拉玛依市;吐鲁番地区;哈密地区;昌吉回族自治州;博尔塔拉蒙古自治州;巴音郭楞蒙古自治州;阿克苏地区;克孜勒苏柯尔克孜自治州;喀什地区;和田地区;伊犁哈萨克自治州;塔城地区;阿勒泰地区;石河子市;阿拉尔市;图木舒克市;五家渠市;台北市;高雄市;台南市;台中市;基隆市;新竹市;嘉义市;地级县市;香港岛;九龙;新界;澳门半岛;离岛;海外;");
            $('#selectedareas').val("北京市;天津市;石家庄市;唐山市;秦皇岛市;邯郸市;邢台市;保定市;张家口市;承德市;沧州市;廊坊市;衡水市;太原市;大同市;阳泉市;长治市;晋城市;朔州市;晋中市;运城市;忻州市;临汾市;吕梁市;呼和浩特市;包头市;乌海市;赤峰市;通辽市;鄂尔多斯市;呼伦贝尔市;巴彦淖尔市;乌兰察布市;兴安盟;锡林郭勒盟;阿拉善盟;沈阳市;大连市;鞍山市;抚顺市;本溪市;丹东市;锦州市;营口市;阜新市;辽阳市;盘锦市;铁岭市;朝阳市;葫芦岛市;长春市;吉林市;四平市;辽源市;通化市;白山市;松原市;白城市;延边朝鲜族自治州;哈尔滨市;齐齐哈尔市;鸡西市;鹤岗市;双鸭山市;大庆市;伊春市;佳木斯市;七台河市;牡丹江市;黑河市;绥化市;大兴安岭地区;上海市;南京市;无锡市;徐州市;常州市;苏州市;南通市;连云港市;淮安市;盐城市;扬州市;镇江市;泰州市;宿迁市;杭州市;宁波市;温州市;嘉兴市;湖州市;绍兴市;金华市;衢州市;舟山市;台州市;丽水市;合肥市;芜湖市;蚌埠市;淮南市;马鞍山市;淮北市;铜陵市;安庆市;黄山市;滁州市;阜阳市;宿州市;六安市;亳州市;池州市;宣城市;福州市;厦门市;莆田市;三明市;泉州市;漳州市;南平市;龙岩市;宁德市;南昌市;景德镇市;萍乡市;九江市;新余市;鹰潭市;赣州市;吉安市;宜春市;抚州市;上饶市;济南市;青岛市;淄博市;枣庄市;东营市;烟台市;潍坊市;济宁市;泰安市;威海市;日照市;莱芜市;临沂市;德州市;聊城市;滨州市;菏泽市;郑州市;开封市;洛阳市;平顶山市;安阳市;鹤壁市;新乡市;焦作市;濮阳市;许昌市;漯河市;三门峡市;南阳市;商丘市;信阳市;周口市;驻马店市;武汉市;黄石市;十堰市;宜昌市;襄阳市;鄂州市;荆门市;孝感市;荆州市;黄冈市;咸宁市;随州市;恩施土家族苗族自治州;仙桃市;潜江市;天门市;神农架林区;长沙市;浏阳市;株洲市;湘潭市;衡阳市;邵阳市;岳阳市;常德市;张家界市;益阳市;郴州市;永州市;怀化市;娄底市;湘西土家族苗族自治州;广州市;韶关市;深圳市;珠海市;汕头市;佛山市;江门市;湛江市;茂名市;肇庆市;惠州市;梅州市;汕尾市;河源市;阳江市;清远市;东莞市;中山市;潮州市;揭阳市;云浮市;南宁市;柳州市;桂林市;梧州市;北海市;防城港市;钦州市;贵港市;玉林市;百色市;贺州市;河池市;来宾市;崇左市;海口市;三亚市;五指山市;琼海市;儋州市;文昌市;万宁市;东方市;定安县;屯昌县;澄迈县;临高县;白沙黎族自治县;昌江黎族自治县;乐东黎族自治县;陵水黎族自治县;保亭黎族苗族自治县;琼中黎族苗族自治县;西沙群岛;南沙群岛;中沙群岛的岛礁及其海域;重庆市;成都市;自贡市;攀枝花市;泸州市;德阳市;绵阳市;广元市;遂宁市;内江市;乐山市;南充市;眉山市;宜宾市;广安市;达州市;雅安市;巴中市;资阳市;阿坝藏族羌族自治州;甘孜藏族自治州;凉山彝族自治州;贵阳市;六盘水市;遵义市;安顺市;铜仁地区;黔西南布依族苗族自治州;毕节地区;黔东南苗族侗族自治州;黔南布依族苗族自治州;昆明市;曲靖市;玉溪市;保山市;昭通市;丽江市;普洱市;临沧市;楚雄彝族自治州;红河哈尼族彝族自治州;文山壮族苗族自治州;西双版纳傣族自治州;大理白族自治州;德宏傣族景颇族自治州;怒江傈僳族自治州;迪庆藏族自治州;拉萨市;昌都地区;山南地区;日喀则地区;那曲地区;阿里地区;林芝地区;西安市;铜川市;宝鸡市;咸阳市;渭南市;延安市;汉中市;榆林市;安康市;商洛市;兰州市;嘉峪关市;金昌市;白银市;天水市;武威市;张掖市;平凉市;酒泉市;庆阳市;定西市;陇南市;临夏回族自治州;甘南藏族自治州;西宁市;海东地区;海北藏族自治州;黄南藏族自治州;海南藏族自治州;果洛藏族自治州;玉树藏族自治州;海西蒙古族藏族自治州;银川市;石嘴山市;吴忠市;固原市;中卫市;乌鲁木齐市;克拉玛依市;吐鲁番地区;哈密地区;昌吉回族自治州;博尔塔拉蒙古自治州;巴音郭楞蒙古自治州;阿克苏地区;克孜勒苏柯尔克孜自治州;喀什地区;和田地区;伊犁哈萨克自治州;塔城地区;阿勒泰地区;石河子市;阿拉尔市;图木舒克市;五家渠市;台北市;高雄市;台南市;台中市;基隆市;新竹市;嘉义市;地级县市;香港岛;九龙;新界;澳门半岛;离岛;海外;");
        }
    }

    function renderCategoryType(obj) {
        var index = obj.options[obj.selectedIndex].value;
        var html = "<option value='0'>请选择顶级分类</option>";
        if (index == 0) {
            $("#pcate").html(html);
        } else {
            $.ajax({
                url: "/category/manage/getCategorysByType",
                data: {"type": index},
                dataType: "json",
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        html += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                    }
                    $("#pcate").html(html);
                }
            })
        }
    }

    function productTypeChange() {
        var productType = $("input[name='productType']:checked").val();
        if (productType == 6) {
            $("#waimaiType").css("display", "block");
            $("#commodityType").css("display", "none");
            $("#waimaiPriceType").css("display", "block");
            $("#commodityPrice").css("display", "none");

            $("#suggestsaleprice").val("")
            $("#marketprice").val("")
            $("#productprice").val("")
            $("#offlineprice").val("")
            $("#costprice").val("")

            $("input[name='isnew']").prop("checked", false);
            $("input[name='ishot']").prop("checked", false);
            $("input[name='ismao']").prop("checked", false);
        } else {
            $("#waimaiType").css("display", "none");
            $("#commodityType").css("display", "block");
            $("#waimaiPriceType").css("display", "none");
            $("#commodityPrice").css("display", "block");

            $("#discount1").css("display", "block");
            $("#discount2").css("display", "block");

            $("#zitiprice").val("")
            $("#tangshiprice").val("")
            $("#waimaiprice").val("")
            $("#waimaiproductprice").val("")
            $("#tangshivipprice").val("")
            $("#waimaivipprice").val("")
            $("#zitivipprice").val("")

            $("input[name='isziti']").prop("checked", false);
            $("input[name='istangshi']").prop("checked", false);
            $("input[name='iswaimai']").prop("checked", false);
            $("input[name='discountStatus']:checked").prop("checked", false);
            $("#discount").val("")

        }
    }

    function iszitiChange() {
        var isziti = $("input[name='isziti']:checked").val();
        if (isziti == 1) {
            $("#ziti").css("display", "block");
        } else {
            $("#ziti").css("display", "none");
            $("#zitiprice").val("")
            $("#zitivipprice").val("")
        }
    }

    function istangshiChange() {
        var istangshi = $("input[name='istangshi']:checked").val();
        if (istangshi == 1) {
            $("#tangshi").css("display", "block");
            $("#discount1").css("display", "block");
            $("#discount2").css("display", "block");
        } else {
            $("#tangshi").css("display", "none");
            $("#tangshiprice").val("")
            $("#tangshivipprice").val("")
            $("input[name='discountStatus']:checked").prop("checked", false);
            $("#discount").val("")
        }
    }

    function iswaimaiChange() {
        var iswaimai = $("input[name='iswaimai']:checked").val();
        if (iswaimai == 1) {
            $("#waimai").css("display", "block");
        } else {
            $("#waimai").css("display", "none");
            $("#waimaiproductprice").val("")
            $("#waimaiprice").val("")
            $("#waimaivipprice").val("")
        }
    }

    function toCategoryOne() {
        // iframe层
        layer.open({
            id: 'group_add',
            type: 2,
            title: '选择顶级分类',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: '/category/manage/toCategory?idDom=pcate&nameDom=pcateName&singleSelect=1&callback=pcateCallback&count=1' // iframe的url
        });
    }

    function toCategoryTwo() {
        var parentid = $("#pcate").val();
        if (!parentid) {
            layer.msg("请选择顶级分类");
            return;
        }
        // iframe层
        layer.open({
            id: 'group_add',
            type: 2,
            title: '选择下级分类',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: '/category/manage/toCategory?idDom=ccate&nameDom=ccateName&singleSelect=1&callback=pcateCallback&count=2&parentid=' + parentid // iframe的url
        });
    }

    function pcateCallback(obj) {
        $("#" + obj.nameDom).val(obj.nameStrs);
        $("#" + obj.idDom).val(obj.idStrs);
        if (obj.count == 1) {
            $("#ccate").val("");
            $("#ccateName").val("");
        }
    }

    function categoryCloseClick(event) {
        if (event == 'one') { // 一级分类清空
            $("#pcateName").val('')
            $("#pcate").val('')
            $("#ccateName").val('')
            $("#ccate").val('')
        } else { // 二级分类清空
            $("#ccateName").val('')
            $("#ccate").val('')

        }
    }

</script>

</body>
</html>
